package com.ftg.shopping.login.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.login.mapper.loginMapper;
import com.ftg.shopping.person.entity.sp_personinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class loginService {

    @Autowired
    loginMapper loginMapper;

    /**
     * 登陆
     * @param spp
     * @return
     */
    public LayuiPage<sp_personinfo> login(sp_personinfo spp){
        IPage<sp_personinfo> ip=new Page<>();
        LayuiPage lp=new LayuiPage(ip);
        QueryWrapper qw=new QueryWrapper();
        Map<String,Object> map=new HashMap<>();
        map.put("username",spp.personid);
        map.put("password",spp.personname);
        qw.allEq(map);
        if(loginMapper.selectList(qw).isEmpty()){
            lp.setMsg("failure");
            return lp;
        }else{
            lp.setMsg("success");
            lp.setData(loginMapper.selectList(qw));
            return lp;
        }
    }

    /**
     * 一级菜单
     * @param userid
     * @return
     */
    public LayuiPage showForPara1(int userid){
        return loginMapper.showForPara1(userid);
    }

    /**
     * 二级菜单
     * @param id
     * @param userid
     * @return
     */
    public LayuiPage showForPara2(int id,int userid){
        return loginMapper.showForPara2(id,userid);
    }

    /**
     * 显示欢迎***登陆
     * @param userid
     * @return
     */
    public Map<String,Object> getPersonName(String userid){
        return loginMapper.getPersonName(userid);
    }
}
